package com.tucc.hello.other.majornum;

/**
 * @Description:
 * @Date: 2021/5/13 08:42
 * @Author: tucc
 */
public class MainjorNum {

    public static void main(String[] args) {
        printTest(1, 2, 3, 1);
        printTest(1, 2, 1, 1);
        printTest(1, 2, 2, 3);
        printTest(1, 2, 1);
        printTest(1, 2, 1, 3);
    }

    public static void printTest(int... arr) {
        System.out.println(query(arr));
    }


    public static int query(int[] arr) {
        if (arr != null && arr.length > 0) {
            int num = arr[0];
            int count = 1;
            for (int i = 1; i < arr.length; i++) {
                if(count == 0){
                    num = arr[i];
                    count = 1;
                    continue;
                }
                if (arr[i] != num) {
                    count--;
                } else {
                    count++;
                }
            }
            return num;
        }
        return -1;
    }
}
